<?php

/**
 * This is the model class for table "article".
 *
 * The followings are the available columns in table 'article':
 * @property string $article_id
 * @property integer $cat_id
 * @property string $title
 * @property string $content
 * @property string $keywords
 * @property string $author
 * @property string $author_email
 * @property string $create_time
 * @property integer $sort_order
 * @property integer $status
 *
 * The followings are the available model relations:
 * @property ArticleCat $cat
 */
class Article extends CommonAR
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Article the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	public function getResourceName()
	{
		return '文章';
	}
	
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'article';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cat_id, sort_order, status', 'numerical', 'integerOnly'=>true),
			array('title, author_email', 'length', 'max'=>50),
			array('keywords', 'length', 'max'=>100),
			array('author', 'length', 'max'=>20),
			array('author_email', 'email',),
			array('content, desc, create_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('article_id, cat_id, title, content, keywords, desc, author, author_email, create_time, sort_order, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'cat' => array(self::BELONGS_TO, 'ArticleCat', 'cat_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'article_id' => '文章ID',
			'cat_id' => '分类',
			'title' => '标题',
			'content' => '内容',
			'keywords' => '关键词',
			'desc' => '文章摘要',
			'author' => '作者',
			'author_email' => '作者Email',
			'create_time' => '创建时间',
			'sort_order' => '排序',
			'status' => '状态',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('article_id',$this->article_id,true);
		$criteria->compare('cat_id',$this->cat_id);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('keywords',$this->keywords,true);
		$criteria->compare('desc',$this->desc,true);
		$criteria->compare('author',$this->author,true);
		$criteria->compare('author_email',$this->author_email,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('sort_order',$this->sort_order);
		$criteria->compare('status',$this->status);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
		
		
	}
}